package edu.ccut.saturn.workflow.startWorkFlowModule.code;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import edu.ccut.saturn.component.IParameterContext;
import edu.ccut.saturn.component.SaturnComponentException;
import edu.ccut.saturn.component.SaturnData;
import edu.ccut.saturn.operation.Operation;
import edu.ccut.saturn.workflow.common.Constants;
import edu.ccut.saturn.workflow.common.WorkFlowTools;
import edu.ccut.saturn.workflow.model.ActivityInfo;

public class GetParticipantFromChange implements IParticipantGeter {

	@SuppressWarnings("unchecked")
	public List<SaturnData> getParticipant(SaturnData workItemInstance,
			ActivityInfo currentActivityInfo, IParameterContext parameterContext)
			throws Exception {
		Connection conn = parameterContext.getConnection();
		List<SaturnData> wiParticipantDatas = new ArrayList<SaturnData>();
		ArrayList<String> userSerialNoList = (ArrayList<String>)parameterContext.getParameterValue(2);
		for(String userSerialNo:userSerialNoList){
			//查询参与者其他信息
			/*String sql ="select * from saturn_authority_user where id ='"+userSerialNo+"'";
			ArrayList<SaturnData> userList = Operation.dataBase().queryBySQL(Constants.SATURNDATA_WF_SATURN_AUTH_USER, sql, conn);*/
			HashMap<String,Object> paramMap = new HashMap<String, Object>();
			paramMap.put("id", userSerialNo);
			ArrayList<SaturnData> userList = Operation.dataBase().queryBySaturnSql(Constants.SATURNDATA_WF_SATURN_AUTH_USER,
					"GET_USER_BY_ID", paramMap, conn);
			SaturnData user = null ;
			String user_serialno =null;
			String username = null;
			if(userList!=null){
				user = userList.get(0);
				user_serialno = user.getString("id");
				username = user.getString("username");
			}else{
				throw new SaturnComponentException("[workflow] customParticipant is invaild");
			}
			SaturnData participantData = WorkFlowTools.getParticipantInstanceWithValues(user_serialno, username);
			wiParticipantDatas.add(participantData);
		}
		return wiParticipantDatas;
	}

}
